package com.lonwin.inspectionmanagement.app.utils;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class StringUtils {
    public StringUtils() {
        throw new AssertionError("你不能初始化工具类");
    }

    /**
     * 格式化小数点
     * @param data
     * @param num
     * @return
     */
    public static  String numFormat(double data,int num)
    {
        try {
            return  new BigDecimal(data).setScale(num, RoundingMode.HALF_UP).toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "0.0";
        }
    }
    /**
     * 判断textView或者EditText 是否为空
     *
     * @param view
     * @return
     */
    public static boolean ViewisEnpty(View view) {
        if (view == null)
            return true;
        if (view instanceof TextView) {
            if (((TextView) view).getText().toString().trim().length() < 1) {
                return true;
            }
            return false;
        }

        if (view instanceof EditText) {
            if (((EditText) view).getText().toString().trim().length() < 1) {
                return true;
            }
            return false;
        }
        return false;
    }
}
